package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetMealController")
@RequestMapping("/user/setmeal")
@Slf4j
public class SetMealController {

    @Autowired
    private SetmealService setmealService;

    //todo admin的setmeal确实，cache也没完全，没有删除
    @Cacheable(cacheNames = "categorySetmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<Setmeal>> getSetmealByCategoryId(Long categoryId) {
        log.info("user get setmeal by categoryId {}", categoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);

        List<Setmeal> setmeals = setmealService.getSetmealsByCondition(setmeal);
        return Result.success(setmeals);
    }

    @Cacheable(cacheNames = "setmealDishItem",key = "#id")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishItemBySetmealId(@PathVariable Long id) {
        log.info("user get dish item by setmeal id {}", id);
        List<DishItemVO> dishItemVOList=setmealService.getDishItemBySetmealId(id);
        return Result.success(dishItemVOList);
    }
}
